﻿using System;
using System.Collections;
using System.Collections.Generic; 
using UnityEngine;
using UnityEngine.UIElements;
using XFABManager;

namespace XFGameFramework.TweenSystem
{ 
    /// <summary>
    /// 动画系统业务逻辑
    /// </summary>
    public class TweenManager
    {
  
        #region 静态方法

        private static List<Tweener> tweeners = new List<Tweener>();

        // key:gameObject HashCode 
        private static Dictionary<int,List<Tweener>> tweeners_dic = new Dictionary<int, List<Tweener>>();

        private static Queue<List<Tweener>> tweeners_queue = new Queue<List<Tweener>>();

        //[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
        //private static void InitTweener()
        //{
        //    tweeners.Clear(); 
        //}


        static TweenManager() 
        {
            UpdateManager.AddUpdateEvent(TweenerUpdate);
        }

        private static void TweenerUpdate()
        {  
            for (int i = tweeners.Count - 1; i >= 0; i--)
            {
                Tweener tweener = tweeners[i];

                tweener.Update();

                if (tweener.isDone) 
                {
                    RemoveTweener(tweener);
                } 
            }

        }

        internal static void KillAll(GameObject gameObject)
        {
            if (!gameObject) return;

            if (!tweeners_dic.ContainsKey(gameObject.GetHashCode())) 
                return;

            List<Tweener> t = tweeners_dic[gameObject.GetHashCode()];

            for (int i = t.Count - 1; i >= 0; i--)
            {
                if (i < 0 || i >= t.Count) continue;
                t[i].Kill();
            }
        }

        internal static void AddTweener(Tweener tweener)
        {
            tweeners.Add(tweener);
            if (tweener.BindingWithGameObject) 
            {
                if(!tweeners_dic.ContainsKey(tweener.GameObjectHashCode))
                    tweeners_dic.Add(tweener.GameObjectHashCode, GetList());

                tweeners_dic[tweener.GameObjectHashCode].Add(tweener);
            } 
        }

        internal static void RemoveTweener(Tweener tweener)
        {
            tweeners.Remove(tweener);
            if (tweener.BindingWithGameObject)
            {
                if (tweeners_dic.ContainsKey(tweener.GameObjectHashCode)) 
                { 
                    tweeners_dic[tweener.GameObjectHashCode].Remove(tweener);
                    if (tweeners_dic[tweener.GameObjectHashCode].Count == 0) 
                    {
                        SetList(tweeners_dic[tweener.GameObjectHashCode]);
                        tweeners_dic.Remove(tweener.GameObjectHashCode);
                    }
                } 
            }
        }


        internal static List<Tweener> GetList() 
        {
            List<Tweener> list = null;

            if(tweeners_queue.Count > 0)
                list = tweeners_queue.Dequeue();
            
            if(list == null)
                list = new List<Tweener>(); 
            //Debug.LogFormat("拿到集合:{0}", list.GetHashCode()); 
            return list;
        }

        internal static void SetList(List<Tweener> tweeners) 
        {
            //Debug.LogFormat("放入集合:{0}", tweeners.GetHashCode());
            tweeners.Clear();
            tweeners_queue.Enqueue(tweeners);
        }

        #endregion
         

         
         
        /// <summary>
        /// 渐变0-1
        /// </summary>
        /// <param name="duration">持续时间</param>
        /// <param name="loop">循环模式</param>
        /// <param name="ease">缓动曲线</param>
        /// <param name="curve">自定义缓动曲线</param>
        /// <param name="ingoreTimeScale">是否忽略时间缩放</param>
        /// <param name="delay">延迟时间</param>
        /// <param name="loopCount">循环次数(小于等于0代表一直循环)</param>
        /// <returns></returns>
        public static TweenerCore<float> Tween01(float duration, LoopMode loop = LoopMode.Once, Ease ease = Ease.Linear, AnimationCurve curve = null, bool ingoreTimeScale = false, float delay = 0, int loopCount = -1)
        { 
            return Tween01(null, duration, loop, ease, curve, ingoreTimeScale, delay, loopCount);
        }

        /// <summary>
        /// 渐变0-1(绑定游戏物体,如果游戏物体被销毁或隐藏,动画会被中断)
        /// </summary>
        /// <param name="gameObject">绑定的游戏物体</param>
        /// <param name="duration">持续时间</param>
        /// <param name="loop">循环模式</param>
        /// <param name="ease">缓动曲线</param>
        /// <param name="curve">自定义缓动曲线</param>
        /// <param name="ingoreTimeScale">是否忽略时间缩放</param>
        /// <param name="delay">延迟时间</param>
        /// <param name="loopCount">循环次数(小于等于0代表一直循环)</param>
        /// <returns></returns>
        public static TweenerCore<float> Tween01(GameObject gameObject,float duration, LoopMode loop = LoopMode.Once, Ease ease = Ease.Linear, AnimationCurve curve = null, bool ingoreTimeScale = false, float delay = 0, int loopCount = -1)
        { 
            return Tween(gameObject,0f,1.0f,duration,loop ,ease,curve,ingoreTimeScale,delay,loopCount);
        }

        /// <summary>
        /// float类型的渐变
        /// </summary>
        /// <param name="from">初始值</param>
        /// <param name="to">目标值</param>
        /// <param name="duration">持续时间</param>
        /// <param name="loop">循环模式</param>
        /// <param name="ease">缓动曲线</param>
        /// <param name="curve">自定义缓动曲线</param>
        /// <param name="ingoreTimeScale">是否忽略时间缩放</param>
        /// <param name="delay">延迟时间</param>
        /// <param name="loopCount">循环次数(小于等于0代表一直循环)</param>
        /// <returns></returns>
        public static TweenerCore<float> Tween(float from, float to, float duration, LoopMode loop = LoopMode.Once, Ease ease = Ease.Linear, AnimationCurve curve = null, bool ingoreTimeScale = false, float delay = 0, int loopCount = -1) 
        { 
            return Tween(null,from,to,duration,loop,ease,curve,ingoreTimeScale,delay,loopCount);
        }

        /// <summary>
        /// float类型的渐变(绑定游戏物体,如果游戏物体被销毁或隐藏,动画会被中断)
        /// </summary>
        /// <param name="gameObject">绑定的游戏物体</param>
        /// <param name="from">初始值</param>
        /// <param name="to">目标值</param>
        /// <param name="duration">持续时间</param>
        /// <param name="loop">循环模式</param>
        /// <param name="ease">缓动曲线</param>
        /// <param name="curve">自定义缓动曲线</param>
        /// <param name="ingoreTimeScale">是否忽略时间缩放</param>
        /// <param name="delay">延迟时间</param>
        /// <param name="loopCount">循环次数(小于等于0代表一直循环)</param>
        /// <returns></returns>
        public static TweenerCore<float> Tween(GameObject gameObject, float from, float to, float duration, LoopMode loop = LoopMode.Once, Ease ease = Ease.Linear, AnimationCurve curve = null, bool ingoreTimeScale = false, float delay = 0, int loopCount = -1)
        {
            TweenerCore<float> t = TweenFloat(gameObject);

            t.From = from;
            t.To = to;

            t.Duration = duration;
            t.LoopMode = loop;
            t.Ease = ease;
            t.Curve = curve;
            t.IgnoreTimeScale = ingoreTimeScale;
            t.Delay = delay;
            t.LoopCount = loopCount;

            t.Play();

            return t;
        }

        /// <summary>
        /// Vector2类型的渐变
        /// </summary>
        /// <param name="from">初始值</param>
        /// <param name="to">目标值</param>
        /// <param name="duration">持续时间</param>
        /// <param name="loop">循环模式</param>
        /// <param name="ease">缓动曲线</param>
        /// <param name="curve">自定义缓动曲线</param>
        /// <param name="ingoreTimeScale">是否忽略时间缩放</param>
        /// <param name="delay">延迟时间</param>
        /// <param name="loopCount">循环次数(小于等于0代表一直循环)</param>
        /// <returns></returns>
        public static TweenerCore<Vector2> Tween(Vector2 from, Vector2 to, float duration, LoopMode loop = LoopMode.Once, Ease ease = Ease.Linear, AnimationCurve curve = null, bool ingoreTimeScale = false, float delay = 0, int loopCount = -1)
        { 
            return Tween(null,from,to,duration,loop,ease,curve,ingoreTimeScale,delay,loopCount);
        }

        /// <summary>
        /// Vector2类型的渐变(绑定游戏物体,如果游戏物体被销毁或隐藏,动画会被中断)
        /// </summary>
        /// <param name="gameObject">绑定的游戏物体</param>
        /// <param name="from">初始值</param>
        /// <param name="to">目标值</param>
        /// <param name="duration">持续时间</param>
        /// <param name="loop">循环模式</param>
        /// <param name="ease">缓动曲线</param>
        /// <param name="curve">自定义缓动曲线</param>
        /// <param name="ingoreTimeScale">是否忽略时间缩放</param>
        /// <param name="delay">延迟时间</param>
        /// <param name="loopCount">循环次数(小于等于0代表一直循环)</param>
        /// <returns></returns>
        public static TweenerCore<Vector2> Tween(GameObject gameObject, Vector2 from, Vector2 to, float duration, LoopMode loop = LoopMode.Once, Ease ease = Ease.Linear, AnimationCurve curve = null, bool ingoreTimeScale = false, float delay = 0, int loopCount = -1)
        { 

            TweenerCore<Vector2> tweener = TweenVector2(gameObject);

            tweener.From = from;
            tweener.To = to;
            tweener.Duration = duration;
            tweener.LoopMode = loop;
            tweener.Ease = ease;
            tweener.Curve = curve;
            tweener.IgnoreTimeScale = ingoreTimeScale;
            tweener.Delay = delay;
            tweener.LoopCount = loopCount;

            tweener.Play();
            return tweener;
        }

        /// <summary>
        /// Vector3类型的渐变
        /// </summary>
        /// <param name="from">初始值</param>
        /// <param name="to">目标值</param>
        /// <param name="duration">持续时间</param>
        /// <param name="loop">循环模式</param>
        /// <param name="ease">缓动曲线</param>
        /// <param name="curve">自定义缓动曲线</param>
        /// <param name="ingoreTimeScale">是否忽略时间缩放</param>
        /// <param name="delay">延迟时间</param>
        /// <param name="loopCount">循环次数(小于等于0代表一直循环)</param>
        /// <returns></returns>
        public static TweenerCore<Vector3> Tween(Vector3 from, Vector3 to, float duration, LoopMode loop = LoopMode.Once, Ease ease = Ease.Linear, AnimationCurve curve = null, bool ingoreTimeScale = false, float delay = 0, int loopCount = -1)
        { 
            return Tween(null,from,to,duration,loop,ease,curve,ingoreTimeScale,delay, loopCount);
        }

        /// <summary>
        /// Vector3类型的渐变(绑定游戏物体,如果游戏物体被销毁或隐藏,动画会被中断)
        /// </summary>
        /// <param name="gameObject">绑定的游戏物体</param>
        /// <param name="from">初始值</param>
        /// <param name="to">目标值</param>
        /// <param name="duration">持续时间</param>
        /// <param name="loop">循环模式</param>
        /// <param name="ease">缓动曲线</param>
        /// <param name="curve">自定义缓动曲线</param>
        /// <param name="ingoreTimeScale">是否忽略时间缩放</param>
        /// <param name="delay">延迟时间</param>
        /// <param name="loopCount">循环次数(小于等于0代表一直循环)</param>
        /// <returns></returns>
        public static TweenerCore<Vector3> Tween(GameObject gameObject,Vector3 from, Vector3 to, float duration, LoopMode loop = LoopMode.Once, Ease ease = Ease.Linear, AnimationCurve curve = null, bool ingoreTimeScale = false, float delay = 0, int loopCount = -1)
        { 
         
            TweenerCore<Vector3> tweener = TweenVector3(gameObject);

            tweener.From = from;
            tweener.To = to;
            tweener.Duration = duration;
            tweener.LoopMode = loop;
            tweener.Ease = ease;
            tweener.Curve = curve;
            tweener.IgnoreTimeScale = ingoreTimeScale;
            tweener.Delay = delay;
            tweener.LoopCount = loopCount;

            tweener.Play();
            return tweener; 
        }

        /// <summary>
        /// Quaternion类型的渐变
        /// </summary>
        /// <param name="from">初始值</param>
        /// <param name="to">目标值</param>
        /// <param name="duration">持续时间</param>
        /// <param name="loop">循环模式</param>
        /// <param name="ease">缓动曲线</param>
        /// <param name="curve">自定义缓动曲线</param>
        /// <param name="ingoreTimeScale">是否忽略时间缩放</param>
        /// <param name="delay">延迟时间</param>
        /// <param name="loopCount">循环次数(小于等于0代表一直循环)</param>
        /// <returns></returns>
        public static TweenerCore<Quaternion> Tween(Quaternion from, Quaternion to, float duration, LoopMode loop = LoopMode.Once, Ease ease = Ease.Linear, AnimationCurve curve = null, bool ingoreTimeScale = false, float delay = 0, int loopCount = -1)
        {
            return Tween(null,from,to,duration,loop,ease,curve,ingoreTimeScale,delay, loopCount); 
        }

        /// <summary>
        /// Quaternion类型的渐变(绑定游戏物体,如果游戏物体被销毁或隐藏,动画会被中断)
        /// </summary>
        /// <param name="gameObject">绑定的游戏物体</param>
        /// <param name="from">初始值</param>
        /// <param name="to">目标值</param>
        /// <param name="duration">持续时间</param>
        /// <param name="loop">循环模式</param>
        /// <param name="ease">缓动曲线</param>
        /// <param name="curve">自定义缓动曲线</param>
        /// <param name="ingoreTimeScale">是否忽略时间缩放</param>
        /// <param name="delay">延迟时间</param>
        /// <param name="loopCount">循环次数(小于等于0代表一直循环)</param>
        /// <returns></returns>
        public static TweenerCore<Quaternion> Tween(GameObject gameObject,Quaternion from, Quaternion to, float duration, LoopMode loop = LoopMode.Once, Ease ease = Ease.Linear, AnimationCurve curve = null, bool ingoreTimeScale = false, float delay = 0, int loopCount = -1)
        {
            //TweenerCore<Quaternion> tweener = Tween<Quaternion>(gameObject,from, to, duration, loop, ease, curve, ingoreTimeScale, delay, loopCount);

            //tweener.onTween -= OnTweenQuaternion;
            //tweener.onTween += OnTweenQuaternion;
            //tweener.Play();

            TweenerCore<Quaternion> tweener = TweenQuaternion(gameObject);

            tweener.From = from;
            tweener.To = to;
            tweener.Duration = duration;
            tweener.LoopMode = loop;
            tweener.Ease = ease;
            tweener.Curve = curve;
            tweener.IgnoreTimeScale = ingoreTimeScale;
            tweener.Delay = delay;
            tweener.LoopCount = loopCount;

            tweener.Play();
            return tweener; 
        }

        /// <summary>
        /// Color类型的渐变
        /// </summary>
        /// <param name="from">初始值</param>
        /// <param name="to">目标值</param>
        /// <param name="duration">持续时间</param>
        /// <param name="loop">循环模式</param>
        /// <param name="ease">缓动曲线</param>
        /// <param name="curve">自定义缓动曲线</param>
        /// <param name="ingoreTimeScale">是否忽略时间缩放</param>
        /// <param name="delay">延迟时间</param>
        /// <param name="loopCount">循环次数(小于等于0代表一直循环)</param>
        /// <returns></returns>
        public static TweenerCore<Color> Tween(Color from, Color to, float duration, LoopMode loop = LoopMode.Once, Ease ease = Ease.Linear, AnimationCurve curve = null, bool ingoreTimeScale = false, float delay = 0, int loopCount = -1)
        { 
            return Tween(null,from,to,duration,loop,ease,curve,ingoreTimeScale,delay, loopCount);
        }

        /// <summary>
        /// Color类型的渐变(绑定游戏物体,如果游戏物体被销毁或隐藏,动画会被中断)
        /// </summary>
        /// <param name="gameObject">绑定的游戏物体</param>
        /// <param name="from">初始值</param>
        /// <param name="to">目标值</param>
        /// <param name="duration">持续时间</param>
        /// <param name="loop">循环模式</param>
        /// <param name="ease">缓动曲线</param>
        /// <param name="curve">自定义缓动曲线</param>
        /// <param name="ingoreTimeScale">是否忽略时间缩放</param>
        /// <param name="delay">延迟时间</param>
        /// <param name="loopCount">循环次数(小于等于0代表一直循环)</param>
        /// <returns></returns>
        public static TweenerCore<Color> Tween(GameObject gameObject,Color from, Color to, float duration, LoopMode loop = LoopMode.Once, Ease ease = Ease.Linear, AnimationCurve curve = null, bool ingoreTimeScale = false, float delay = 0, int loopCount = -1)
        {  
            TweenerCore<Color> tweener = TweenColor(gameObject);

            tweener.From = from;
            tweener.To = to;
            tweener.Duration = duration;
            tweener.LoopMode = loop;
            tweener.Ease = ease;
            tweener.Curve = curve;
            tweener.IgnoreTimeScale = ingoreTimeScale;
            tweener.Delay = delay;
            tweener.LoopCount = loopCount;

            tweener.Play();
            return tweener; 
        }

        internal static TweenerCore<float> ComponentTween(Component component, float from, float to, float duration, LoopMode loop, Ease ease, AnimationCurve curve, bool ingoreTimeScale, Action<TweenerCore<float>> onValueChange,float delay,float progress=0, int loopCount = -1)
        {  
            TweenerCore<float> tweener = TweenFloat(component);

            tweener.From = from;
            tweener.To = to;
            tweener.Duration = duration;
            tweener.LoopMode = loop;
            tweener.Ease = ease;
            tweener.Curve = curve;
            tweener.IgnoreTimeScale = ingoreTimeScale;
            tweener.Delay = delay;
            tweener.LoopCount = loopCount;

            tweener.onValueChange -= onValueChange;
            tweener.onValueChange += onValueChange;

            tweener.Play(progress);
            return tweener; 
        }

        internal static TweenerCore<Vector2> ComponentTween(Component component, Vector2 from, Vector2 to, float duration, LoopMode loop, Ease ease, AnimationCurve curve, bool ingoreTimeScale, Action<TweenerCore<Vector2>> onValueChange,float delay, float progress = 0, int loopCount = -1)
        {
            TweenerCore<Vector2> tweener = TweenVector2(component);

            tweener.From = from;
            tweener.To = to;
            tweener.Duration = duration;
            tweener.LoopMode = loop;
            tweener.Ease = ease;
            tweener.Curve = curve;
            tweener.IgnoreTimeScale = ingoreTimeScale;
            tweener.Delay = delay;
            tweener.LoopCount = loopCount;

            tweener.onValueChange -= onValueChange;
            tweener.onValueChange += onValueChange;

            tweener.Play(progress);
            return tweener;
        }
        internal static TweenerCore<Vector3> ComponentTween(Component component, Vector3 from, Vector3 to, float duration, LoopMode loop, Ease ease, AnimationCurve curve, bool ingoreTimeScale, Action<TweenerCore<Vector3>> onValueChange,float delay, float progress = 0, int loopCount = -1)
        {
            TweenerCore<Vector3> tweener = TweenVector3(component);

            tweener.From = from;
            tweener.To = to;
            tweener.Duration = duration;
            tweener.LoopMode = loop;
            tweener.Ease = ease;
            tweener.Curve = curve;
            tweener.IgnoreTimeScale = ingoreTimeScale;
            tweener.Delay = delay;
            tweener.LoopCount = loopCount;

            tweener.onValueChange -= onValueChange;
            tweener.onValueChange += onValueChange;

            tweener.Play(progress);
            return tweener;
        }
         
        internal static TweenerCore<Quaternion> ComponentTween(Component component, Quaternion from, Quaternion to, float duration, LoopMode loop, Ease ease, AnimationCurve curve, bool ingoreTimeScale, Action<TweenerCore<Quaternion>> onValueChange,float delay, float progress = 0, int loopCount = -1)
        {
            TweenerCore<Quaternion> tweener = TweenQuaternion(component);

            tweener.From = from;
            tweener.To = to;
            tweener.Duration = duration;
            tweener.LoopMode = loop;
            tweener.Ease = ease;
            tweener.Curve = curve;
            tweener.IgnoreTimeScale = ingoreTimeScale;
            tweener.Delay = delay;
            tweener.LoopCount = loopCount;

            tweener.onValueChange -= onValueChange;
            tweener.onValueChange += onValueChange;

            tweener.Play(progress);
            return tweener;
        }

        internal static TweenerCore<Color> ComponentTween(Component component, Color from, Color to, float duration, LoopMode loop, Ease ease, AnimationCurve curve, bool ingoreTimeScale, Action<TweenerCore<Color>> onValueChange,float delay, float progress = 0, int loopCount = -1)
        {
            TweenerCore<Color> tweener = TweenColor(component);

            tweener.From = from;
            tweener.To = to;
            tweener.Duration = duration;
            tweener.LoopMode = loop;
            tweener.Ease = ease;
            tweener.Curve = curve;
            tweener.IgnoreTimeScale = ingoreTimeScale;
            tweener.Delay = delay;
            tweener.LoopCount = loopCount;

            tweener.onValueChange -= onValueChange;
            tweener.onValueChange += onValueChange;

            tweener.Play(progress);
            return tweener;
        }
  
        private static void OnTweenFloat(Tweener tweener) 
        {
            TweenerCore<float> t = tweener as TweenerCore<float>;
            if (t == null) return;
            t.Value = Mathf.LerpUnclamped(t.From, t.To, t.progress);
        }

        private static void OnTweenVector2(Tweener tweener)
        {
            TweenerCore<Vector2> t = tweener as TweenerCore<Vector2>;
            if (t == null) return;
            t.Value = Vector2.LerpUnclamped(t.From, t.To, t.progress);
        }

        private static void OnTweenVector3(Tweener tweener) 
        {
            TweenerCore<Vector3> t = tweener as TweenerCore<Vector3>;
            if (t == null) return;
            t.Value = Vector3.LerpUnclamped(t.From,t.To,t.progress);
        }

        private static void OnTweenQuaternion(Tweener tweener) 
        {
            TweenerCore<Quaternion> t = tweener as TweenerCore<Quaternion>;
            if (t == null) return;
            t.Value = Quaternion.LerpUnclamped(t.From, t.To, t.progress);
        }

        private static void OnTweenColor(Tweener tweener)
        {
            TweenerCore<Color> t = tweener as TweenerCore<Color>;
            if (t == null) return;
            t.Value = Color.LerpUnclamped(t.From, t.To, t.progress);
        }
         
        public static TweenerCore<float> TweenFloat()
        {
            TweenerCore<float> tweener = new TweenerCore<float>();
            tweener.onTween -= OnTweenFloat;
            tweener.onTween += OnTweenFloat;
            return tweener;
        }

        public static TweenerCore<float> TweenFloat(GameObject gameObject) 
        {
            TweenerCore<float> tweener = TweenFloat();
            tweener.GameObject = gameObject;
            return tweener;
        }

        public static TweenerCore<float> TweenFloat(Component component)
        {
            TweenerCore<float> tweener = TweenFloat(component.gameObject);
            tweener.Component = component;
            return tweener;
        }

        public static TweenerCore<Vector2> TweenVector2() 
        {
            TweenerCore<Vector2> tweener = new TweenerCore<Vector2>();
            tweener.onTween -= OnTweenVector2;
            tweener.onTween += OnTweenVector2;
            return tweener;
        }

        public static TweenerCore<Vector2> TweenVector2(GameObject gameObject) 
        {
            TweenerCore<Vector2> t = TweenVector2();
            t.GameObject = gameObject;
            return t;
        }

        public static TweenerCore<Vector2> TweenVector2(Component component) 
        {
            TweenerCore<Vector2> t = TweenVector2(component.gameObject);
            t.Component = component;
            return t;
        }

        public static TweenerCore<Vector3> TweenVector3() 
        {
            TweenerCore<Vector3> tweener = new TweenerCore<Vector3>();

            tweener.onTween -= OnTweenVector3;
            tweener.onTween += OnTweenVector3;
            return tweener;
        }


        public static TweenerCore<Vector3> TweenVector3(GameObject gameObject)
        {
            TweenerCore<Vector3> t = TweenVector3();
            t.GameObject = gameObject;
            return t;
        }


        public static TweenerCore<Vector3> TweenVector3(Component component)
        {
            TweenerCore<Vector3> t = TweenVector3(component.gameObject);
            t.Component = component;
            return t;
        }


        public static TweenerCore<Quaternion> TweenQuaternion()
        {
            TweenerCore<Quaternion> tweener = new TweenerCore<Quaternion>();

            tweener.onTween -= OnTweenQuaternion;
            tweener.onTween += OnTweenQuaternion;
            return tweener;
        }

        public static TweenerCore<Quaternion> TweenQuaternion(GameObject gameObject) 
        {
            TweenerCore<Quaternion> t = TweenQuaternion();
            t.GameObject = gameObject;
            return t;
        }

        public static TweenerCore<Quaternion> TweenQuaternion(Component component)
        {
            TweenerCore<Quaternion> t = TweenQuaternion(component.gameObject);
            t.Component = component;
            return t;
        }



        public static TweenerCore<Color> TweenColor()
        {
            TweenerCore<Color> tweener = new TweenerCore<Color>();

            tweener.onTween -= OnTweenColor;
            tweener.onTween += OnTweenColor;
            return tweener;
        }

        public static TweenerCore<Color> TweenColor(GameObject gameObject) 
        {
            TweenerCore<Color> t = TweenColor();
            t.GameObject =gameObject;
            return t;
        }

        public static TweenerCore<Color> TweenColor(Component component)
        {
            TweenerCore<Color> t = TweenColor(component.gameObject);
            t.Component =component;
            return t;
        }

    }

}


